package NiMIngCLass;



/**
 * 局部内部类限制类的使用
 */



/**
 * 局部内部类限制类的使用
 */
        public class TestLocal {
            public static void main(String[] args) {
//学校开设新班
                //需要高级的老师
//        Teacher teacher =new TallTeacher();
//        teacher.teach();
                //校方没有这么多的高级老师,校方出台了一个规则
                //按照奇数偶数的来分,奇数为初级,偶数为高级
                Teacher t = School.getTeacher(1);
                t.teach();
            }
        }
        class School {
            public static Teacher getTeacher(int classNo) {
                //初级老师(局部内部类)
                class DiTeacher extends Teacher {
                    public void teach() {
                        System.out.println("老师在上课");
                    }
                }




//                //高级老师(匿名内部类)
//               class TallTeacher extends Teacher {
//                    public void teach() {
//                        System.out.println("高级老师在上课");
//                    }
//                }
                Teacher currentTeacher = null;//返回值



                if (classNo % 2 != 0) {
                    currentTeacher = new DiTeacher();
                } else {
                    //匿名内部类
                    //创键了一个高级老师对象,是Teacher的子类.实现了teacher()方法
                    currentTeacher = new Teacher(){
                        public void teach() {
                            System.out.println("高级老师在上课");
                        }
                    };
                }
                return currentTeacher;
            }
        }
        abstract class Teacher {
            public abstract void teach();


        }

